<?php
declare(strict_types=1);
/**
 * @project: 兔兔找图微信小程序
 * @author: kert
 * @date: 2023/5/16
 * @link: https://www.tutudati.com/
 * @site: 微信搜索-兔兔找图
 */

namespace App\Admin\Controllers\User;

use App\Admin\Actions\Author\IdentAudit;
use App\Models\Admin\User\Author;
use App\Models\CommonUser\UserProfession;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Grid;

class AuthorController extends AdminController
{
    protected $title = "作者认证";

    public function grid(): Grid
    {
        $grid = new Grid(new Author());

        $grid->filter(function ($filter) {
            $filter->disableIdFilter();
            $filter->column(1 / 2, function ($filter) {
                $filter->like('nickname', "作者名称");
                $filter->like('user.nickname', "用户名称");
                $filter->equal("audit_status", "审核状态")->select([3 => '待审核中', 1 => '审核通过', 2 => '审核驳回']);
                $filter->equal("is_forbidden", "账号状态")->select([2 => '启用', 1 => '禁用']);
                $filter->equal("gender", "用户性别")->select(['保密', '男', '女']);
            });
            $filter->column(1 / 2, function ($filter) {
                $filter->between('series_count', "作品数量");
                $filter->between('created_at', "认证时间")->datetime();
                $filter->between('birthday', "用户生日")->date();
                $filter->equal("profession", "用户职业")->select(UserProfession::getList());
            });
        });
        $grid->model()->orderByDesc("audit_status");
        $grid->column("uid", "作者编号")->copyable();
        $grid->column("qr_url", "作者头像")->lightbox(['width' => 50, 'height' => 50]);
        $grid->column("nickname", "作者昵称");
        $grid->column("user.nickname", "用户昵称");
        $grid->column("profession.title", "作者专业");
        $grid->column("birthday", "生日");
        $grid->column("constellation", "星座");
        $grid->column("gender", "用户性别")->display(function ($gender) {
            if ($gender == 1) {
                return "<span style='color:blue'>男</span>";
            }
            if ($gender == 2) {
                return "<span style='color:#FFB6C1'>女</span>";
            }
            return "<span style='color:gray'>未知</span>";
        });
        $grid->column("audit_status", "审核状态")->display(function ($audit_status) {
            if ($audit_status == 1) {
                return "<span style='color:green'>审核通过</span>";
            }
            if ($audit_status == 2) {
                return "<span style='color:red'>审核驳回</span>";
            }
            return "<span style='color:gray'>待审核中</span>";
        });
        $grid->column("is_forbidden", "账号状态")->display(function ($is_forbidden) {
            if ($is_forbidden == 2) {
                return "<span style='color:green'>启用</span>";
            }
            if ($is_forbidden == 1) {
                return "<span style='color:red'>禁用</span>";
            }
            return "<span style='color:gray'>未知</span>";
        });
        $grid->column("created_at", "注册时间");
        $grid->column("audit_at", "审核时间");

        $grid->disableExport();
        $grid->actions(function ($actions) {
            $actions->disableView();
            $actions->disableDelete();
            $actions->disableEdit();
            $actions->add(new IdentAudit());
        });
        $grid->disableCreateButton();

        return $grid;
    }
}
